﻿using ERP.Framework.Components.ConfigurationHelper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ERP.Framework.Components.ConfigurationHelper;

namespace ERP.Framework.Components.Testing
{
    
    
    /// <summary>
    ///This is a test class for ConfigurationManagerTest and is intended
    ///to contain all ConfigurationManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ConfigurationManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ExceptionHandlerSettings
        ///</summary>
        [TestMethod()]
        public void ConfigurationManager_ExceptionHandlerSettingsTest()
        {
            ConfigurationHelper.CustomSettings.ExceptionHandlerSettings actual =
                ConfigurationHelper.ConfigurationManager.ExceptionHandlerSettings;
            Assert.IsNotNull(actual);
            Assert.AreNotEqual(actual.ErrorLogFilePath, string.Empty);
            Assert.AreEqual(actual.ErrorLogFilePath, @"c:\Log\ErrorLog.xml");

            Assert.AreNotEqual(actual.ErrorLogType, string.Empty);
            Assert.AreEqual(actual.ErrorLogType, 1);

            Assert.AreNotEqual(actual.ErrorLogName, string.Empty);
            Assert.AreEqual(actual.ErrorLogName, "ERP");
        }

        /// <summary>
        ///A test for UserInterfaceSettings
        ///</summary>
        [TestMethod()]
        public void ConfigurationManager_UISettingsTest()
        {
            ConfigurationHelper.CustomSettings.UISettings actual = ConfigurationHelper.ConfigurationManager.UserInterfaceSettings;
            Assert.IsNotNull( actual);
            Assert.AreEqual(actual.CurrentUICulture, "en-US");
        }

        /// <summary>
        ///A test for SortingSettings
        ///</summary>
        [TestMethod()]
        public void ConfigurationManager_SortingSettingsTest()
        {
            ConfigurationHelper.CustomSettings.SortingSettings actual = ConfigurationManager.SortingSettings;
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.SortingAlgorithm ,0 );
        }

        /// <summary>
        ///A test for ConnectionSettings
        ///</summary>
        [TestMethod()]
        public void ConfigurationManager_DatabaseConfigurationSettingsTest()
        {
            ConfigurationHelper.CustomSettings.DatabaseConfigurationSettings actual = ConfigurationManager.ConnectionSettings;
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Databases);
            Assert.IsNotNull(actual.Databases["AdministrationDB"]);
            Assert.AreNotEqual(actual.Databases["AdministrationDB"].ConnectionString, string.Empty);
            Assert.AreNotEqual(actual.Databases["AdministrationDB"].Provider, string.Empty);
        }

        /// <summary>
        ///A test for ConfigurationSettings
        ///</summary>
        [TestMethod()]
        public void ConfigurationManager_ConfigurationSettingsTest()
        {
            ConfigurationHelper.CustomSettings.ConfigurationSettings actual = ConfigurationManager.ConfigurationSettings;
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.UseExternalConfigFile, false);
            Assert.AreEqual(actual.ExternalConfigurationFilePath, string.Empty);
        }

        /// <summary>
        ///A test for GetValue
        ///</summary>
        [TestMethod()]
        public void ConfigurationManager_GetValueTest()
        {
            string key = "GenericSetting"; 
            string expected = "Generic"; 
            string actual;
            actual = ConfigurationManager.GetValue(key);            
            Assert.AreEqual(expected, actual);            
        }
    }
}
